package com.kingtsoft.study.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
@Component
public class GlobalInterceptor implements HandlerInterceptor {

	    @Override
	    public void afterCompletion(HttpServletRequest request,HttpServletResponse response, Object object, Exception exception)throws Exception {
	    }

	    /**
	     * 在调用controller具体方法后拦截
	     */
	    @Override
	    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object object,ModelAndView modelAndView) throws Exception {

	    }

	    @Override
	    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object object) throws Exception {
	    	
//    		SysUser u = (SysUser) request.getSession().getAttribute(ConfigConstants.LOCAL_CLINET_USER);
// 	        if (u == null) {
// 	        	String requestType = request.getHeader("X-Requested-With"); 
// 	        	//XMLHttpRequest
// 	        	if(StringUtils.isNoneBlank(requestType)&&requestType.equals("XMLHttpRequest")){//判断是ajax请求session过期
// 	        		throw new AuthenticationException(DescribableEnum.EXPIREDSESSION);
// 	        	}else{
// 	        		response.sendRedirect(request.getContextPath() + "/admin");
// 	        	}
// 	           
// 	        } else {
// 	            //SessionHolder.set(ConfigConstants.LOCAL_CLINET_USER, u);
// 	        }
 	        return true;
	    }

}
